import * as actionTypes from '../action_types';

let user =JSON.parse(localStorage.getItem('user'))
let token =localStorage.getItem('token')
const defaultState = {
    user: user || {},
    token: token || '',
    isLogin: user && token ? true : false,
    isFull: false,
    weatherObj:{}
};
const Reducer = (state = defaultState, action) => {
    const { type, data} = action
    let newState = JSON.parse(JSON.stringify(state));
    switch (type) {
        case actionTypes.SAVE_USER_INFO:
            newState.user =data.user;
            newState.token=data.token;
            newState.isLogin=true;
            return newState;
        case actionTypes.DELETE_USER_INFO:
            newState.user ={};
            newState.token='';
            newState.isLogin=false;
            return newState;
        case actionTypes.CHANGE_FULL_SCREEN:
            newState.isFull = !newState.isFull;
            return newState;
        case actionTypes.CHANGE_WEATHER:
            newState.weatherObj =action.weatherObj;
            return newState;
        default:
            return state;
    }

}
export default Reducer;
